<@ms.html5>
<style>
	.table-hover{
		table-layout:fixed;
	}
	.table-hover td{
		overflow:hidden;
		text-overflow:ellipsis;
		white-space:nowrap;
	}
</style>
	<@ms.nav title="服务单位" back=true></@ms.nav>
	<@ms.panel>
				<@ms.searchForm  name="searchForm" id="searchForm" action="${managerPath}/enterprise/list.do">
						<@ms.text label="服务单位名称"   name="enterpriseName"  title="请输入服务单位名称"  placeholder="请输入服务单位名称" value="${enterpriseName?default('')}"   />
						<@ms.text label="联系人"   name="enterpriseContact"  title="请输入联系人"  placeholder="请输入联系人" value="${enterpriseContact?default('')}"   />
						<@ms.text label="联系电话"   name="enterpriseTel"  title="请输入联系电话"  placeholder="请输入联系电话" value="${enterpriseTel?default('')}"   />
						<@ms.searchFormButton>
								<@ms.queryButton id="submitSearch"/>								
						</@ms.searchFormButton>
				</@ms.searchForm>
				
				<@ms.table head=['<th class="text-center" width="5%">序号</th>','<th class="text-center" width="15%">服务单位名称</th>','<th class="text-center" width="18%">地址</th>','<th class="text-center" width="8%">联系人</th>','<th class="text-center" width="8%">联系电话</th>','<th class="text-center" width="12%">主营品牌</th>','<th class="text-center" width="8%">资质类别</th>','<th class="text-center" width="10%">认证</th>','<th class="text-center" width="8%">服务评分</th>','<th class="text-center" width="8%">操作</th>']>
						<#if enterpriseList?has_content>
		        			<#list enterpriseList as enterprise>
		           				<tr>
		           					<td class="text-center">${enterprise_index+1}</td>
						            <td class="text-center" title="${enterprise.enterpriseName?default("-")}">${enterprise.enterpriseName?default("-")}</td>
						            <td class="text-center" title="${enterprise.enterpriseAddress?default("-")}">${enterprise.enterpriseAddress?default("-")}</td>
						            <td class="text-center" title="${enterprise.enterpriseContact?default("-")}">${enterprise.enterpriseContact?default("-")}</td>
						            <td class="text-center" title="${enterprise.enterpriseTel?default("-")}">${enterprise.enterpriseTel?default("-")}</td>
						            <td class="text-center" title="${enterprise.enterpriseBrand?default("-")}">${enterprise.enterpriseBrand?default("-")}</td>
						            <td class="text-center" title="${enterprise.enterpriseQualification?default("-")}">${enterprise.enterpriseQualification?default("-")}</td>
						            <td class="text-center" title="${enterprise.enterpriseCertification?default("-")}">${enterprise.enterpriseCertification?default("-")}</td>
						            <td class="text-center" title="<#if enterprise.enterpriseScore??>#{enterprise.enterpriseScore;m1M1}</#if>"><#if enterprise.enterpriseScore??>#{enterprise.enterpriseScore;m1M1}</#if></td>
						            <td class="text-center"><@ms.button value="绑定" icon="cog" class="btn btn-success" onclick="showBindModel('${enterprise.id}','${enterprise.enterpriseName}','${enterprise.peopleId?default('')}','${enterprise.nickName?default('')}','${enterprise.headimgUrl?default('')}');" title="帐号绑定"/></td>
						        </tr>
		           			</#list>
		           		<#else>	
			           		<tr>
						         <td colspan="10" class="text-center">
						            <@ms.nodata/>
								</td>
					        </tr>
		           		</#if>
					</@ms.table>
					<!--分页样式 开始-->
					<#if page?has_content>
						<@ms.pagehelper page=page url="${managerPath}/enterprise/list.do?${params}"/>
					</#if>	
		<!--帐号模态框开始-->
		<@ms.modal modalName="bindModel" title="帐号绑定" size="M">
			<@ms.modalBody >
			<@ms.form isvalidation=true name="updateBind" action="">
			<@ms.text id="enterpriseNameModel" label="服务单位名称：" readonly="readonly"/>
			<@ms.hidden id="enterpriseIdModel" name="enterpriseIdModel" />
			<@ms.hidden id="peopleIdModel" name="peopleIdModel" />
			<div class="form-group ms-form-group">	
				<label class="col-sm-3 control-label">
					管理员帐号：
				</label>		
				<div class="col-sm-9 ms-from-group-input ms-form-input" style="">
					<input style="width:86%;display:inline-block;" type="text" autocomplete="off" id="nickNameModel" class="form-control" placeholder="请输入管理员昵称"><@ms.button class="btn btn-default" value="验证" onclick="getPeople();"/>
					<span id="imageModel" style="display:none"><img id="headimgUrlModel" src="" style="width:30%"/></span>
				</div>
			</div>
			</@ms.form>	
		    </@ms.modalBody>
		    <@ms.modalButton>
		    	<@ms.savebutton id="bindButton" value="绑定" onclick="bindPeople();"/> 
	    		<@ms.button value="关闭" onclick="$('.bindModel').modal('hide');"/>  
	 		</@ms.modalButton>
		</@ms.modal>
		<!--帐号模态框结束-->
	</@ms.panel>
</@ms.html5>
<script>
	$(function(){
		$("form[name='updateBind']").parent().css("height","260px");
		
		//根据条件查询服务单位
		$("#submitSearch").click(function() {
			$("#searchForm")[0].submit();
		});
	});
	//js监听回车键 
	document.onkeydown = function(e) {
		e = e ? e : window.event;
		var keyCode = e.which ? e.which : e.keyCode;
		if (keyCode == 13) {
			$("#searchForm")[0].submit();
		}
	}
	function showBindModel(id, enterpriseName,peopleId,nickName,headimgUrl){
		$('.bindModel').modal('show');
		$('#enterpriseIdModel').val(id);
		$('#enterpriseNameModel').val(enterpriseName);
		$('#peopleIdModel').val(peopleId);
		$('#nickNameModel').val(nickName);
		if(nickName!=''){
			$('#imageModel').show();
			$('#headimgUrlModel').attr('src',headimgUrl);
		}else{
			$('#imageModel').hide();
		}
		}
		function getPeople(){
			var nickName = $("#nickNameModel").val();
			if(nickName==''){
				alert('请输入管理员昵称！');
				$("#nickNameModel").focus();
				return false;
			}
			$.ajax({
				type: "post",
				dataType: "json",
				url: base+"${baseManager}/enterprise/getPeople.do",
				data:"nickName="+nickName,
				beforeSend:function() {
		 		},
		 		success: function(msg){
					if(msg.result){
						var people = msg.resultData;
						if(typeof(people)=='undefined'){
							alert("未找到用户");
							$('#imageModel').hide();
							$('#peopleIdModel').val('');
						}else{
							$('#imageModel').show();
							$('#nickNameModel').val(people.peopleUserNickName);
							$('#peopleIdModel').val(people.peopleId);
							$('#headimgUrlModel').attr('src',people.weixinPeopleHeadimgUrl);
						}
					} else {
						alert("未找到用户");
						$('#imageModel').hide();
						$('#peopleIdModel').val('');
					}
				},
				error:function(){
					alert("未找到用户");
					$('#imageModel').hide();
					$('#peopleIdModel').val('');
				}
			});
		}
		function bindPeople(){
			var enterpriseId = $('#enterpriseIdModel').val();
			var peopleId = $('#peopleIdModel').val();
			var nickName = $('#nickNameModel').val();
			if(enterpriseId=='' || peopleId=='' || nickName==''){
				alert('用户不存在');
				return false;
			}
			$.ajax({
				type: "post",
				dataType: "json",
				url: base+"${baseManager}/enterprise/bindPeople.do",
				data:"enterpriseId="+enterpriseId+"&peopleId="+peopleId,
				beforeSend:function() {
					$("#bindButton").text("绑定中");
					$("#bindButton").attr("disabled",true);
		 		},
		 		success: function(msg){
					if(msg.result){
						alert("绑定成功");
	   					location.reload();
					} else {
						alert("绑定失败，系统异常");
						$("#bindButton").text("绑定");
						$("#bindButton").attr("disabled",false);
					}
				},
				error:function(){
					alert("绑定失败，请刷新重试");
					$("#bindButton").text("绑定");
					$("#bindButton").attr("disabled",false);
				}
			});
		}
</script>